/*
	SensorInfo - Copyright (C) 2010  Luca Minuti

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

*/

/*
	Implementation of the main sensor information
*/

package it.mondogufo.sensorinfo;

import java.util.*;
import android.hardware.*;
import android.util.Log;

/*
	SensorInfo hold all information about a sensor
*/
public class SensorInfo {
	
	private String name;
	
	private String vendor;
	
	private int type;
	
	private float[] values;
	
	private static final String AccelerometerFormat = "x-axis: <b>%.2f</b>  - y-axis: <b>%.2f</b> - z-axis: <b>%.2f</b>";
	private static final String OrientationFormat = "Azimuth: <b>%.2f</b> - Pitch: <b>%.2f</b> - Roll: <b>%.2f</b>";

	private static final String MagneticFileFormat = "<b>%.2f</b> uT";
	private static final String LightFormat = "<b>%.2f</b> lux";
	private static final String ProximityFormat = "<b>%.2f</b> cm (or close/far)";
	
	public SensorInfo(String name, String vendor) {
		super();
		this.name = name;
		this.vendor = vendor;
		this.type = Sensor.TYPE_ALL;
	}

	public SensorInfo(Sensor sensor) {
		super();
		this.name = sensor.getName();
		this.vendor = sensor.getVendor();
		this.type = sensor.getType();
	}
	
	public String getName() {
		return this.name;
	}
	
	public String getVendor() {
		return this.vendor;
	}

	public int getType() {
		return this.type;
	}
	
	public float[] getValues() {
		return this.values;
	}
	
	public void setValues(float[] aValues) {
		this.values = aValues;
	}
	
	public String getHtmlValue() {
		String value;
		if ( (values == null) || (values.length < 1) )
			return "...";
		switch (type) {
			case Sensor.TYPE_ORIENTATION: 
				value = String.format(OrientationFormat, values[0], values[1], values[2]);
				break;
			case Sensor.TYPE_ACCELEROMETER: 
				value = String.format(AccelerometerFormat, values[0], values[1], values[2]);
				break;
			case Sensor.TYPE_MAGNETIC_FIELD: 
				value = String.format(MagneticFileFormat, values[0]);
				break;
			case Sensor.TYPE_LIGHT: 
				value = String.format(LightFormat, values[0]);
				break;
			case Sensor.TYPE_PROXIMITY: 
				value = String.format(ProximityFormat, values[0]);
				break;
			default:  
				int i;
				value = "";
				for (i = 0 ; i < values.length ; i++) {
					value = value + "<b>" + Float.toString(values[i]) + "</b>   ";
				}
		}
		return value;
	}
}
